<!-- 省级区划组件
使用：
1）import Ss01003Tag from '@/components/system/ss01003-select'

2）components: {
             Ss01003Tag
        },
3） <Ss01003Tag
                        :bindshengjiData.sync="searchInfo.bindData"
                        :bindshijiData.sync="searchInfo.bindshijiData"
                        :shengji_value="sel_xqval"
                        :shiji_value="sel_jdval"
                        :shiji_disabled="jd_disabled"
                        :shengji_disabled="xq_disabled"/>
-->
<template>
    <Row style="min-width: 350px">
        <i-col span="10">
            <Select v-model="shengjiSelected" clearable placeholder="请选择省级" :disabled="shengji_select_disabled">
                <Option v-for="item in shengjiList" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
        </i-col>
        <i-col span="14">
            <Select v-model="shijiSelected" clearable placeholder="请选择市级" :disabled="shiji_select_disabled">
                <Option v-for="item in shijiSelectedList" :value="item.value" :key="item.value">{{ item.label }}
                </Option>
            </Select>
        </i-col>
    </Row>
</template>
<script>
    import {postAction} from '@/api/request'

    export default {
        name: 'Ss01003Tag',
        //父组件调用入参
        props: {
            //省级默认选中的value
            shengji_value: {
                type: String,
                required: false
            },
            //市级默认选中的value
            shiji_value: {
                type: String,
                required: false
            },
            //市级 是否可用
            shiji_disabled: {
                type: Boolean,
                required: false
            },
            //省级是否可用
            shengji_disabled: {
                type: Boolean,
                required: false
            },
        },
        data() {
            return {
                shiji_displayed: true,
                shengji_displayed: true,
                shiji_select_disabled: false,
                shengji_select_disabled: false,
                shengjiSelected: '',
                shijiSelected: '',
                shengjiList: [],
                shijiList: [],
                shijiSelectedList: [],
            }
        },
        methods: {},
        mounted: function () {
        },
        watch: {

            shiji_disabled(newvalue, oldvalue) {
                this.shiji_select_disabled = newvalue
            },
            shengji_disabled(newvalue, oldvalue) {
                this.shengji_select_disabled = newvalue
            },
            shengji_value(newvalue, oldvalue) {
                //监控入参
                //conso.log("接收shengji_value:"+newvalue)
                this.shengjiSelected = newvalue;

                if (newvalue != undefined) {
                    //回传给父组件
                    this.$emit("update:bindshengjiData", newvalue)
                } else {
                    this.$emit("update:bindshengjiData", "")
                }
            },
            shiji_value(newvalue, oldvalue) {
                //监控入参
                //conso.log("接收shiji_value:"+newvalue)
                this.shijiSelected = newvalue;
                if (newvalue != undefined) {
                    this.$emit("update:bindshijiData", newvalue)
                } else {
                    //如果页面点击取消 市级下拉框，则返回省级选中值
                    this.$emit("update:bindshijiData", "")
                }
            },
            shengjiSelected: function () {
                // 清除市级
                this.shijiSelected = '';
                this.shijiSelectedList = [];
                //设置该省级下的市级
                for (let j = 0, len = this.shijiList.length; j < len; j++) {
                    if (this.shengjiSelected == this.shijiList[j].parentId) {
                        this.shijiSelectedList.push(this.shijiList[j]);
                    }
                }
                ////默认选中【2】
                //conso.log("watch shengji_value::"+ this.shengji_value)
                //conso.log("watch shengjiSelected::"+ this.shengjiSelected)
                if (this.shengji_value != undefined && this.shiji_value != undefined) {
                    this.shijiSelected = this.shiji_value;
                }
                if (this.shengjiSelected != undefined) {
                    //回传给父组件
                    this.$emit("update:bindshengjiData", this.shengjiSelected)
                } else {
                    this.$emit("update:bindshengjiData", "")
                }
            },
            shijiSelected: function () {
                if (this.shijiSelected != undefined) {
                    this.$emit("update:bindshijiData", this.shijiSelected)
                } else {
                    //如果页面点击取消 市级下拉框，则返回省级选中值
                    this.$emit("update:bindshijiData", this.shijiSelected)
                }
            }
        },
        created() {
            //初始化
            var that = this;
            var dataParam = {}
            postAction('/api/ac/subsistence/ss01003Service/findQhList', dataParam).then((res) => {
                that.shengjiList = res.data.data.shengji;
                that.shijiList = res.data.data.shiji;
            }).finally(() => {
                //如配置则默认选中对应的下拉框
                if (that.shengji_value != undefined) {
                    that.shengjiSelected = that.shengji_value;
                }
                if (that.shiji_value != undefined) {
                    that.shijiSelected = that.shiji_value;
                }
            })
            that.shiji_select_disabled = that.shiji_disabled
            that.shengji_select_disabled = that.shengji_disabled
        }
    }
</script>
